home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / vbcc / machines / amiga68k / libsrc / amigalib / timedelay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  1.1 KB  |  42 lines

  1. #include <exec/memory.h>
  2. #include <devices/timer.h>
  3. #include <clib/alib_protos.h>
  4. #include <clib/exec_protos.h>
  5.  
  6. struct PortIO
  7. {
  8.   struct timerequest treq;
  9.   struct MsgPort port;
  10. };
  11.  
  12. LONG TimeDelay(long unit, unsigned long secs, unsigned long microsecs)
  13. {
  14.   struct PortIO *portio;
  15.   long ret=-1;
  16.  
  17.   if ((portio=(struct PortIO *)AllocMem(sizeof(struct PortIO),MEMF_CLEAR|MEMF_PUBLIC)))
  18.   {
  19.     portio->port.mp_Node.ln_Type=NT_MSGPORT;
  20.     if ((BYTE)(portio->port.mp_SigBit=AllocSignal(-1))<0)
  21.     {
  22.       portio->port.mp_SigTask=FindTask(NULL);
  23.       NewList(&portio->port.mp_MsgList);
  24.  
  25.       portio->treq.tr_node.io_Message.mn_Node.ln_Type=NT_MESSAGE;
  26.       portio->treq.tr_node.io_Message.mn_ReplyPort=&portio->port;
  27.       if (!(OpenDevice(TIMERNAME,unit,&portio->treq.tr_node,0)))
  28.       {
  29.         portio->treq.tr_node.io_Command=TR_ADDREQUEST;
  30.         portio->treq.tr_time.tv_secs=secs;
  31.         portio->treq.tr_time.tv_micro=microsecs;
  32.         if (!DoIO(&portio->treq.tr_node))
  33.           ret=0;
  34.         CloseDevice(&portio->treq.tr_node);
  35.       }
  36.       FreeSignal(portio->port.mp_SigBit);
  37.     }
  38.     FreeMem(portio,sizeof(struct PortIO));
  39.   }
  40.   return ret;
  41. }
  42.